{template 'web/'.$cfg['floder'].'/base_menu'}
<div class="top_tab"> 
  <a href="{php echo $this->createWebUrl('shop')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">管理店铺</a> 
  <a href="{php echo $this->createWebUrl('shop',array('op'=>'post'))}" class="layui-btn {if $operation != 'post'}layui-btn-primary{/if}">添加店铺</a> 
  <div class="secrchinput">
    <button><i class="fa fa-search"></i></button>
    <input type="text" id="txtTopupSeachStr" placeholder="输入">
  </div>
</div>
{if $operation == 'post'}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
<input type="hidden" name="id" value="{php echo $id}" />
  <div class="panelbox-head">
  	{if !$id}添加新店铺{else}编辑【{$category['companyname']}】{/if}
      {if $id}
      <a href="{$_W['siteroot']}app/index.php?i={$_W['uniacid']}&c=entry&do=placeorder&m=j_hmoney&shopid={php echo $id}" target="_blank" class="layui-btn layui-btn-primary">扫码点餐链接</a>
      <a href="{$_W['siteroot']}app/index.php?i={$_W['uniacid']}&c=entry&do=phone&m=j_hmoney&shopid={php echo $id}" target="_blank" class="layui-btn layui-btn-primary">服务员点餐链接</a>
      {/if}
  </div>
  <div class="panelbox-body">
  	<div class="layui-tab">
      <ul class="layui-tab-title">
        <li class="layui-this">基本内容</li>
        <li>支付方式</li>
        <li>积分设置</li>
        <li>其他</li>
        <li>充值设置</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" lay-verify="required" name="companyname" value="{$category['companyname']}"/>
              <div class="help-block">店铺名称，请勿重复</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">LOGO</label>
            <div class="layui-input-block">
              {php echo tpl_form_field_image('logo', $category['logo']);}
              <div class="help-block">收银前台左上角logo</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">二维码</label>
            <div class="layui-input-block">
              {php echo tpl_form_field_image('qrcode', $category['qrcode']);}
              <div class="help-block">建议放公众号二维码</div>
            </div>
          </div>
        </div>
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <label class="layui-form-label">自定义支付方式</label>
            <div class="layui-input-block form-inline">
              <div class="input-group">
                <span class="input-group-addon">自定义1</span>
                <input type="text" class="form-control" name="custom_pay1" value="{$category['custom_pay1']}"/>
              </div>
              <div class="input-group">
                <span class="input-group-addon">自定义2</span>
                <input type="text" class="form-control" name="custom_pay2" value="{$category['custom_pay2']}"/>
              </div>
              <div class="input-group">
                <span class="input-group-addon">自定义3</span>
                <input type="text" class="form-control" name="custom_pay3" value="{$category['custom_pay3']}"/>
              </div>
              <div class="input-group">
                <span class="input-group-addon">自定义4</span>
                <input type="text" class="form-control" name="custom_pay4" value="{$category['custom_pay4']}"/>
              </div>
              <div class="help-block">自定义支付方式。如美团团购券等的使用。</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
              <input type="checkbox" name="custom_pay1_status" value="1" {if $category['custom_pay1_status']}checked{/if} title="自定义支付1">
              <input type="checkbox" name="custom_pay2_status" value="1" {if $category['custom_pay2_status']}checked{/if} title="自定义支付2">
              <input type="checkbox" name="custom_pay3_status" value="1" {if $category['custom_pay3_status']}checked{/if} title="自定义支付3">
              <input type="checkbox" name="custom_pay4_status" value="1" {if $category['custom_pay4_status']}checked{/if} title="自定义支付4">
              <div class="help-block">只有打勾的支付方式前台方可使用</div>
            </div>
          </div>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>银行通道</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">银行商户号</label>
                <div class="layui-input-block">
                    <input type="text" name="bankmch_id" value="{$category['bankmch_id']}" class="layui-input"/>
                    <div class="help-block">银行通道分配的商户号</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">支付密钥</label>
                <div class="layui-input-block">
                    {if $cfg['bankpaykey']}
                    <input type="text" name="bankpaykey1" placeholder="修改密匙请直接输入" class="form-control"/>
                    <input type="hidden" name="bankpaykey" value="{$category['bankpaykey']}"/>
                    {else}
                    <input type="text" name="bankpaykey" value="{$category['bankpaykey']}" class="form-control"/>
                    {/if}
                    <div class="help-block">银行通道分配的支付密钥，基于安全问题，不显示</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">其他商户号</label>
                <div class="layui-input-block">
                    <input type="text" name="customerid" value="{$category['customerid']}" class="layui-input"/>
                    <div class="help-block">没有请留空</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">其他支付密钥</label>
                <div class="layui-input-block">
                    <input type="text" name="customerkey" value="{$category['customerkey']}" class="layui-input"/>
                    <div class="help-block">没有请留空</div>
                </div>
            </div>
          <fieldset class="layui-elem-field layui-field-title">
            <legend>微信参数 <small>其他参数请到参数设置中设置</small></legend>
          </fieldset>
          <div class="layui-form-item">
            <label class="layui-form-label">appid</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="appid" value="{$category['appid']}"/>
                <div class="help-block"></div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">子商户appid</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="sub_appid" value="{$category['sub_appid']}"/>
                <div class="help-block">sub_appid,如果您是服务商，请在这里填写子商户的appid。如果不是服务商，请勿填写！</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">AppSecret</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="appsecret" value="{$category['appsecret']}"/>
                <div class="help-block">服务商的appsecret</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">商户名称</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="pay_name" value="{$category['pay_name']}"/>
                <div class="help-block">商户名称,不能多于6个中文字</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">商户号</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="pay_mchid" value="{$category['pay_mchid']}"/>
                <div class="help-block">商户号(mchid),微信支付商户后台获得</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">子商户号</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="sub_mch_id" value="{$category['sub_mch_id']}"/>
                <div class="help-block">sub_mch_id,如果您是服务商，请在这里填写子商户的商户号。如果不是服务商，请勿填写！</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">商户密钥</label>
            <div class="layui-input-block">
              <input type="text" class="layui-input" name="pay_signkey" value="{$category['pay_signkey']}"/>
                <div class="help-block">微信支付密钥，如果是服务商，请填写子商户的密钥</div>
            </div>
          </div>
          <fieldset class="layui-elem-field layui-field-title">
            <legend>支付宝参数 <small>其他参数请到参数设置中设置</small></legend>
          </fieldset>
          <div class="layui-form-item">
              <label class="layui-form-label">app_id</label>
              <div class="layui-input-block">
                <input type="text" name="app_id" value="{$category['app_id']}" class="layui-input"/>
				<div style="color: red !important;">&#x6B64;&#x6E90;&#x7801;&#x7531;&#xFF1A;&#x5F00;&#x5427;&#x6E90;&#x7801;&#x793E;&#x533A;&#x53D1;&#x5E03;</div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">appAuthToken</label>
              <div class="layui-input-block">
                <input type="text" name="appauthtoken" value="{$category['appauthtoken']}" class="layui-input"/>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">口碑门店ID</label>
              <div class="layui-input-block">
                <input type="text" name="alipay_store_id" value="{$category['alipay_store_id']}" class="layui-input"/>
              </div>
            </div>
        </div>
        
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <label class="layui-form-label">积分类型</label>
            <div class="layui-input-block">
              <div class="input-group"> <span class="input-group-addon">人民币1分钱</span> <span class="input-group-addon">获得</span>
                <input type="text" class='form-control' name='creadit' value='{php echo $category["creadit"] ? $category["creadit"] : 0}'/>
                <span class="input-group-addon">积分</span> </div>
              <div class="help-block">开启后，请在小票上添加|#积分#|内容的二维码。客户扫码二维码获得积分</div>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">积分后按钮</label>
            <div class="layui-input-block">
              <input type="text" class='form-control' name='creditbtn' value='{$category["creditbtn"]}'/>
              <div class="help-block">客户扫码获得积分后，按钮连接的地址</div>
            </div>
          </div>
        </div>
        <div class="layui-tab-item">
        	<div class="layui-form-item">
              <label class="layui-form-label">口味</label>
              <div class="layui-input-block">
                <input type="text" class="layui-input" name="taste" value="{$category['taste']}"/>
                <div class="help-block">请使用|进行分割。</div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">服务类型</label>
              <div class="layui-input-block">
                <input type="text" class="layui-input" name="servicetype" value="{$category['servicetype']}"/>
                <div class="help-block">移动端，客户呼叫服务员的类型，请使用|进行分割，如“加茶水|结账|其他”</div>
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">自定义商品</label>
              <div class="layui-input-block">
                <input type="text" class="layui-input" name="customgood" value="{$category['customgood']}"/>
                <div class="help-block">当收银前端直接输入金额时，可选择改价格商品定义成什么。如服务费、开瓶费等等。最多100个汉字，请使用|进行分割</div>
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">退款原因</label>
              <div class="layui-input-block">
                <input type="text" class="layui-input" name="refundreason" value="{$category['refundreason']}"/>
                <div class="help-block">当发生退款时，可选择的原因。请使用|进行分割</div>
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">最低折扣</label>
              <div class="layui-input-block">
                <input type="text" class="layui-input" name="mindiscount" value="{$category['mindiscount']}"/>
                <div class="help-block">前台收银，手动改价格/折扣，不能低于此值。请输入1-100；0为不限制；100为禁止手动折扣</div>
              </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">厨房打印分单</label>
                <div class="layui-input-block">
                    <input type="checkbox" class="layui-input" value="1" name="printseparate" {if $category['printseparate']}checked{/if} title="分单打印">
                    <div class="help-block">每个菜单独一个打印单</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">区域打印</label>
                <div class="layui-input-block">
                    <input type="checkbox" class="layui-input" value="1" name="isareaprint" {if $category['isareaprint']}checked{/if} title="开启区域打印">
                    <div class="help-block">用于楼层打印机打印。如不清楚，请勿开启</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">厨房总单打印</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="iskitchenprint" value="{$category['iskitchenprint']}"/>
                    <div class="help-block">用于上菜人员核对菜品等信息。如不清楚，请勿开启</div>
                </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">扩展按钮</label>
              <div class="layui-input-block">
                <div id="btnList">
                  {php $btnlist=json_decode($category['btnlist'],true)}
                  {php $i=0}
                  {if count($btnlist)}
                  {loop $btnlist $index $row}
                  <div style="margin-bottom:10px;" id="link-key[{php echo $i}]">
                    <label class='form-inline' >
                      <input class='form-control' name='link-key[{php echo $i}]' required value='{$index}' placeholder='按钮名称'/>
                      :
                      <input class='form-control' name='link-val[{php echo $i}]' required value='{$row}' placeholder='连接'/>
                      <a href="javascript:" onclick="delbtn({$i})"><i class='fa fa-remove-circle'></i></a></label>
                  </div>
                  {php $i++}
                  {/loop}
                  {/if}
                  </div>
                <a href="javascript:addbtn()" class="layui-btn"><i class="icon-plus-sign-alt"></i> 添加</a>
                <div class="help-block">前台扩展按钮</div>
              </div>
            </div>
            
        </div>
        <div class="layui-tab-item">
        	<div class="layui-form-item">
              <label class="layui-form-label">充值活动</label>
              <div class="layui-input-block" >
               <div id="chargeList">
                {php $wxcard=json_decode($category['chargelist'],true)}
                  {php $i=0}
                  {if count($wxcard)}
                  {loop $wxcard $index $row}
                  <div style="margin-bottom:10px">
                    <label class='form-inline' >
                      <input class='form-control' name='charge-key[{php echo $i}]' required value='{$index}' placeholder='充值金额'/>
                      :
                      <input class='form-control' name='charge-val[{php echo $i}]' required value='{$row}' placeholder='赠送金额'/>
                      <a href="javascript:" onclick="delobject(this)"><i class='fa fa-remove-circle'></i></a></label>
                  </div>
                  {php $i++}
                  {/loop}
                  {/if}
                  </div>
                <a href="javascript:addwxcard()" class="layui-btn"><i class="icon-plus-sign-alt"></i> 添加</a>
                <div class="help-block"></div>
              </div>
            </div>
        </div>
      </div>
    </div>
    <div class="panelbox-foot">
    	<input type="hidden" name="token" value="{$_W['token']}" />
    	<input class="layui-btn" type="submit" lay-submit="" name="submit" lay-filter="submitbtn" value="提交">
    </div>
  </div>
  </form>
</div>
<script>
function delobject(obj){
	$(obj).parent().parent().remove();
	//$("#chargeList div").eq((num-1)).remove();;
}
function addwxcard(){
	var index=$("#chargeList input[name^='charge-key']").size()+1;
	var temp="<div  style='margin-bottom:10px'><label class='form-inline'><input class='form-control' name='charge-key["+index+"]' required placeholder='充值金额'/> : <input class='form-control' name='charge-val["+index+"]' required placeholder='赠送金额'/> <a href='javascript:' onclick='delobject(this)'><i class='fa fa-remove-circle'></i></a></label></div>";
	$("#chargeList").append(temp);
}

function delbtn(num){
	$("#btnList div").eq((num-1)).remove();;
}
function addbtn(){
	var index=$("#btnList input[name^='link-key']").size()+1;
	var temp="<div style='margin-bottom:10px'><label class='form-inline'><input class='form-control' name='link-key["+index+"]' required placeholder='按钮名称'/> : <input class='form-control' name='link-val["+index+"]' required placeholder='连接'/> <a href='javascript:delbtn("+index+")'><i class='fa fa-remove-circle'></i></a></label></div>";
	$("#btnList").append(temp);
}

</script>

{else}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
  <input type="hidden" name="id" value="{php echo $id}" />
  <div class="panelbox-head"> 管理店铺 
    <div class="pull-right form-inline">
    	{if $_W['isfounder'] || $_W['role']=="manager"}
    	<select style="display:inline-block;" lay-ignore onchange="jumptoNew(this)">
            <option value="">选择店铺</option>
            {loop $list2 $row}
            <option value="{$row['id']}" {if $row['id']==$shopid} selected{/if}>{$row['companyname']}</option>
            {/loop}
        </select>
        {/if}
    </div>
  </div>
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <colgroup>
          <col width="50">
          <col width="150">
          <col>
          <col align="right">
        </colgroup>
        <thead>
          <tr>
            <th style="width:60px"><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
            <th>名称</th>
            <th>人员数量</th>
            <th style="text-align:right">操作</th>
          </tr>
        </thead>
        <tbody>
          {loop $list $row}
          <tr>
            <td><input type="checkbox" name="" lay-skin="primary"></td>
            <td>{$row['companyname']}</td>
            <td>{php echo intval($userList[$row['id']])}</td>
            <td class="text-right">
            <a href="{php echo $this->createWebUrl('shop',array('op'=>'post','id'=>$row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a>
            <a href="{php echo $this->createWebUrl('shop',array('op'=>'set','id'=>$row['id']))}" class="layui-btn layui-btn-warm layui-btn-small">管理店铺</a>
                {if $_W['isfounder'] || $_W['role']=="manager"}
                <a href="javascript:deleteContent('{php echo $this->createWebUrl('shop',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
                {/if}
            </td>
          </tr>
          {/loop}
        </tbody>
      </table>
    </div>
  </div>
  <div class="panelbox-foot">  </div>
  </form>
</div>

{/if}

<script>
layui.use(['layer', 'laypage', 'element','form'], function(){
  var layer = layui.layer
  ,laypage = layui.laypage
  ,element = layui.element
  ,form = layui.form;
  form.render();
  form.on('submit(submitbtn)', function(data){

    return true;
  });
  form.on('checkbox(allChoose)', function(data){
    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
    child.each(function(index, item){
      item.checked = data.elem.checked;
    });
    form.render('checkbox');
  });
});
function jumtto(obj){
	var value=$(obj).find("option:selected").val();
	if(value){
		var url="";
		var shopid=$(obj).attr("shopid");
		if(value==1){
			url="{php echo $this->createWebUrl('goods',array('op'=>'display'))}";
		}else if(value==2){
			url="{php echo $this->createWebUrl('goods',array('op'=>'categorydisplay'))}";
		}else if(value==3){
			url="{php echo $this->createWebUrl('table',array('op'=>'display'))}";
		}
		location.href=url+"&shopid="+shopid;
	}
}
function jumptoNew(obj){
	var value=$(obj).find("option:selected").val();
	location.href="{php echo $this->createWebUrl('shop',array('op'=>'set'))}&id="+value;
}
function deleteContent(url){
    layer.confirm('确认删除店铺？删除后将不可恢复', {}, function(){
        layer.confirm('请再次确认删除店铺？因为删除后将不可恢复', {}, function(){
            location.href=url;
        });
    });
}
</script>